<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$id=$_SESSION['action_id'];
if($_RQ['op']=='main'){
	exi($return);
}
//某某游戏POST
if($_RQ['op']=='ddp'){
	$return['man']=pdo_getall('jy_h5game_fans',array('rid'=>$id,'uniacid'=>$_SESSION['uniacid'],'sex'=>1,'awardnum'=>0));
	$return['mcount']=count($return['man']);
	$return['woman']=pdo_getall('jy_h5game_fans',array('rid'=>$id,'uniacid'=>$_SESSION['uniacid'],'sex'=>2,'awardnum'=>0));
	$return['wcount']=count($return['woman']);
	$hm=pdo_getall('jy_h5game_fans',array('rid'=>$id,'uniacid'=>$_SESSION['uniacid'],'sex'=>1,'awardnum >'=>0));
	//$hw=pdo_getall('jy_h5game_fans',array('rid'=>$id,'uniacid'=>$_SESSION['uniacid'],'sex'=>2,'awardnum >'=>0));
	$list=array();
	foreach($hm as $v){
		$k=$v['awardnum'];
		$wo=pdo_get('jy_h5game_fans',array('rid'=>$id,'uniacid'=>$_SESSION['uniacid'],'sex'=>2,'awardnum'=>$k));
		$list[$k]=array('mavatar'=>$v['headImg'],'mnickname'=>$v['name'],'wavatar'=>$wo['headImg'],'wnickname'=>$wo['name']);
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='ddp2'){
	$data=get_postdata();
	$hm=pdo_count('jy_h5game_fans',array('rid'=>$id,'uniacid'=>$_SESSION['uniacid'],'sex'=>1,'awardnum >'=>0));
	pdo_update('jy_h5game_fans',array('awardnum'=>$hm+1),array('id'=>$data['mid']));
	pdo_update('jy_h5game_fans',array('awardnum'=>$hm+1),array('id'=>$data['wid']));
	exi($hm+1);
}
if($_RQ['op']=='cj'){
	$data=get_postdata();
	$k=$data['k'];
	$num=$data['num'];
	if(!$num){
		$return['user']=pdo_getall('jy_h5game_fans',array('rid'=>$id,'uniacid'=>$_SESSION['uniacid'],'awardinfo'=>$k));
	
	}else{
	
	$item=pdo_get('jy_h5game_reply',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$user=pdo_getall('jy_h5game_fans',array('rid'=>$id,'uniacid'=>$_SESSION['uniacid'],'awardnum'=>0));
	if(count($user)<$num){
		exi('参与人数不足','error');
	}
	$jx=json_decode($item['award'],true);
	$jp=$jx[$k];
	$zj=array_rand($user,$num);
	$return['user']=array();
	if($num==1){
		$u=$user[$zj];
		$return['user'][]=$u;
		pdo_update('jy_h5game_fans',array('awardinfo'=>$k,'awardnum'=>1),array('id'=>$u['id']));
	}else{
		foreach($zj as $v){
			$u=$user[$v];
			$return['user'][]=$u;
		}
	}
		
	}
	
	exi($return['user']);
}
if($_RQ['op']=='zjd'){
	$data=get_postdata();
	$k=$data['k'];
	$num=$data['num'];
	if(!$num){
		$return['user']=pdo_getall('jy_h5game_fans',array('rid'=>$id,'uniacid'=>$_SESSION['uniacid'],'awardinfo'=>$k));	
	}else{
		$item=pdo_get('jy_h5game_reply',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$user=pdo_getall('jy_h5game_fans',array('rid'=>$id,'uniacid'=>$_SESSION['uniacid'],'awardnum'=>0));
		if(count($user)<$num){
			exi('参与人数不足','error');
		}
		$jx=json_decode($item['award'],true);
		$jp=$jx[$k];
		$zj=array_rand($user,$num);
		$return['user']=array();
		if($num==1){
			$u=$user[$zj];
			$return['user'][]=$u;
			pdo_update('jy_h5game_fans',array('awardinfo'=>$k,'awardnum'=>1),array('id'=>$u['id']));
		}else{
			foreach($zj as $v){
				$u=$user[$v];
				$return['user'][]=$u;
			}
		}	
	}
	exi($return['user']);
}
if($_RQ['op']=='sjh'){
	$data=get_postdata();	
	$num=$data['num'];
	$user=pdo_getall('jy_h5game_fans',array('rid'=>$id,'uniacid'=>$_SESSION['uniacid'],'tel >'=>0));
	if(count($user)<$num){
		exi('摇号不能大于参与人数！','error');
	}
	$in=array_rand($user,$num);
	$return['user']=array();
	if($num==1){
		$u=$user[$in];
		$return['in'][]=$u;
		pdo_update('jy_h5game_fans',array('awardnum'=>1),array('id'=>$u['id']));
	}else{
		foreach($in as $v){
			$u=$user[$v];
			pdo_update('jy_h5game_fans',array('awardnum'=>1),array('id'=>$u['id']));
			$return['in'][]=$u;
		}
	}
	$return['user']=$user;
	$return['num']=count($user);
	exi($return);
}

if($_RQ['op']=='h5_vote'){
	$post=get_postdata();
	$update=array('optid'=>$post['optid']);
	pdo_update('jy_h5game_fans',$update,array('rid'=>$post['rid'],'uniacid'=>$_SESSION['uniacid'],'fansId'=>$_SESSION['uid']));
	$return['type']="success";
	exi($return);
}
if($_RQ['op']=='upaward_userinfo'){
	$post=get_postdata();
	$update=array(
		'ausername'=>$post['ausername'],
		'aphone'=>$post['aphone'],
		'address'=>$post['address'],
	);
	pdo_update('jy_h5game_award',$update,array('id'=>$post['awardid'],'uniacid'=>$_SESSION['uniacid'],'fansID'=>$_SESSION['uid']));
	$return['type']="success";
	exi($return);
}
?>